package com.support;

import org.springframework.core.convert.converter.Converter;

import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZoneOffset;

/**
 * https://www.baeldung.com/java-convert-epoch-localdate
 * https://www.baeldung.com/java-date-to-localdate-and-localdatetime
 */
public enum LongToLocalDateConverter implements Converter<Long, LocalDate> {
    INSTANCE;
    @Override
    public LocalDate convert(Long source) {
        System.out.println("long to LocalDate----");
        Instant instant = Instant.ofEpochMilli(source);
        //ZoneId zoneId = ZoneId.systemDefault(); // Use the system default time zone
        ZoneId zoneId = ZoneOffset.of("+8"); // Use the system default time zone
        LocalDate localDate = instant.atZone(zoneId).toLocalDate();
        return localDate;
    }
}
